<?php
/*------------------------------------------------------------------------
 # com_k2store - K2 Store v 2.6
# ------------------------------------------------------------------------
# author    Ramesh Elamathi - Weblogicx India http://www.weblogicxindia.com
# copyright Copyright (C) 2012 Weblogicxindia.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://k2store.org
# Technical Support:  Forum - http://k2store.org/forum/index.html
-------------------------------------------------------------------------*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
JLoader::register( 'K2StoreTable', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2store'.DS.'tables'.DS.'_base.php' );

class TableAddress extends K2StoreTable
{

	/**
	 * @param database A database connector object
	 */

	function __construct(&$db)
	{

		parent::__construct('#__k2store_address', 'id', $db );
	}


	/**
	 * Checks the entry to maintain DB integrity
	 * @return unknown_type
	 */
	function check()
	{
		$params = &JComponentHelper::getParams('com_k2store');
		
		if($this->type=='billing') {
			if($params->get('bill_fname')==1) {
				if (empty($this->first_name))
				{
					$this->setError( "K2STORE_FIRST_NAME_REQUIRED" );
					return false;
				}
			}

			if($params->get('bill_lname')==1) {
				if (empty($this->last_name))
				{
					$this->setError( "K2STORE_LAST_NAME_REQUIRED" );
					return false;
				}

			}	
			
				if($params->get('bill_addr_line1')==1)
				{
					if (empty($this->address_1))
					{
						$this->setError( "K2STORE_ADDRESS_REQUIRED" );
						return false;
					}
				}
				if($params->get('bill_city')==1)
				{
					if (empty($this->city))
					{
						$this->setError( "K2STORE_CITY_REQUIRED" );
						return false;
					}
				}
				if($params->get('bill_zip')==1)
				{
					if (empty($this->zip))
					{
						$this->setError( "K2STORE_ZIP_REQUIRED" );
						return false;
					}
				}
				if($params->get('bill_country_zone')==1)
				{
					if (empty($this->country_id))
					{
						$this->setError( "K2STORE_SELECT_A_COUNTRY" );
						return false;
					}
				}
				if($params->get('bill_phone1')==1)
				{
					if (empty($this->phone_1))
					{
						$this->setError( "K2STORE_PHONE_REQUIRED" );
						return false;
					}
				}
				
				if($params->get('bill_phone2')==1)
				{
					if (empty($this->phone_2))
					{
						$this->setError( "K2STORE_MOBILE_REQUIRED" );
						return false;
					}
				}

		}
		
		if($this->type=='shipping') {
			if($params->get('ship_fname')==1) {
				if (empty($this->first_name))
			{
				$this->setError( "K2STORE_FIRST_NAME_REQUIRED" );
				return false;
			}
			}
		
			if($params->get('ship_lname')==1) {
				if (empty($this->last_name))
				{
				$this->setError( "K2STORE_LAST_NAME_REQUIRED" );
					return false;
				}
			}
				if($params->get('ship_addr_line1')==1)
				{
					if (empty($this->address_1))
					{
						$this->setError( "K2STORE_ADDRESS_REQUIRED" );
						return false;
					}
				}
				if($params->get('ship_city')==1)
				{
					if (empty($this->city))
					{
						$this->setError( "K2STORE_CITY_REQUIRED" );
						return false;
					}
				}
				if($params->get('ship_zip')==1)
				{
					if (empty($this->zip))
					{
						$this->setError( "K2STORE_ZIP_REQUIRED" );
						return false;
					}
				}
				if($params->get('ship_country_zone')==1)
				{
					if (empty($this->country_id))
					{
						$this->setError( "K2STORE_SELECT_A_COUNTRY" );
						return false;
					}
				}
				if($params->get('ship_phone1')==1)
				{
					if (empty($this->phone_1))
					{
						$this->setError( "K2STORE_PHONE_REQUIRED" );
						return false;
					}
				}
				
				if($params->get('ship_phone2')==1)
				{
					if (empty($this->phone_2))
					{
						$this->setError( "K2STORE_MOBILE_REQUIRED" );
						return false;
					}
				}
		
			
		}
			return true;
	}

}

